package com.esm.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.esm.dao.SelectDeptDao_zxk;
import com.esm.model.Department;
import com.esm.utils.JDBCUtil;
/**
 * 查询部门dao实现
 * @author 康少
 *
 * 2017年1月9日
 */
public class SelectDeptDaoImpl_zxk implements SelectDeptDao_zxk{

	public List<Department> getDeptName() {
		// TODO Auto-generated method stub
		List<Department> departments = new ArrayList<Department>();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT *");
		sql.append(" FROM ems_dept");
		Connection con = JDBCUtil.getConnection();
		PreparedStatement pst = null;
		try {
			pst = con.prepareStatement(sql.toString());
			ResultSet rs = pst.executeQuery();
			while (rs.next()) {
				Department dept = new Department();
				dept.setDep_id(rs.getInt("dep_id"));
				dept.setDep_name(rs.getString("dep_name"));
				departments.add(dept);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JDBCUtil.closeJDBC(pst, con);
		return departments;	
	}

}
